import PAGE from "../../../utils/middleware/page";
import { storeBindingsBehavior } from "mobx-miniprogram-bindings";
import store from "../../../store/index";
const app = getApp();
Page(PAGE({
    behaviors: [storeBindingsBehavior],
    storeBindings: {
        store,
        fields: {
            needRefresh: 'vehicle.needRefresh'
        },
        actions: {
            updateNeedRefresh: 'vehicle.updateNeedRefresh'
        }
    },
    data: {
        list: [],
        apiField: {
            module: "memberFamily",
            api: "List",
            data: "list",
            search: {},
        },
    },
    onLoad() {
        this.fetchData();
    },
    onShow() {
        if (this.data.needRefresh) {
            this.updateNeedRefresh(false);
            this.fetchData();
        }
    },
    onPullDownRefresh() {
        this.fetchData();
        wx.stopPullDownRefresh();
    },
    async fetchData() {
        this.handleFetchData({}, "apiField", true);
    },
    async handleRemove(e) {
        const { id } = e.currentTarget.dataset;
        var _this = this;
        wx.showModal({
            title: "提示",
            content: "确定要移除该家庭成员吗",
            success: async function (showRes) {
                if (showRes.confirm) {
                    _this.toRemove(id);
                }
            },
        });
    },
    async toRemove(id) {
        try {
            const res = await wx.$Api.memberFamily.Delete({
                data: {
                    MemberId: id,
                },
                hasLoading: true,
            });

            this.fetchData();

        } catch (e) {
            wx.$Fun.showToast(e.Message);
        }
    },
})
);
